<?php
require_once('init.php');

if($siteoff == 1){siteMsg($siteoffw);}

require_once('model/class.link.php');
require_once('model/class.user.php');
$qiLink = new qiLink($DB);
$qiUser = new qiUser($DB);

$pageurl = '';
$cid = "1";      //设定首页默认发布话题ID

//微博首页
if($action == ''){

$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$pageurl .= './index.php?page';

require_once('model/class.mlog.php');
require_once('model/class.cates.php');
require_once('model/class.comment.php');
require_once('model/class.attachment.php');

$qiMlog = new qiMlog($DB);
$qiCate = new qiCate($DB);
$qiComment = new qiComment($DB);
$qiAttachment = new qiAttachment($DB);

$mlogs = $qiMlog->getMlog($page,8);

$virtue = "id";
$setvirtue = "id";
$lognum = $qiMlog->getLogNum($virtue, $setvirtue);

foreach($mlogs as $key=>$val)
{
$val['cname'] = $qiCate->getCateName($val['cid']);
$val['truename'] = $qiUser->getUserName($val['uid']);
$val['comms'] = $qiComment->getComments($val['id']);
$val['photo'] = $qiAttachment->getMlogPic($val['aid']);
$mlogs[$key] = $val;
}

$page_url = pagination($lognum, 8, $page, $pageurl);

//最新用户列表(显示最新9条)
$users = $qiUser->getHomeUsers();

//首页友情链接	
$links = $qiLink->getHomeLink();

$xingTemplate->display('index');	
}

//发布微博
if($action == 'addlog')
{
$logcontent = t($_POST['logcontent']);
$aid = $_POST['uploadvalue'];
$ctime = time();
if(empty($logcontent))
{
redirect('index.php', 2, '微博内容不能为空！3秒钟跳转到首页！');
}else
{
require_once('model/class.mlog.php');
$qiMlog = new qiMlog($DB);
$qiMlog->addMlog($cid, $uid, $logcontent,$aid,$ctime);
redirect('index.php', 2, '发布成功，3秒钟跳转到首页！');
}
}

//友情链接页面
if($action == 'links')
{
$title = "友情链接";
$links = $qiLink->getLinks();
$xingTemplate->display('links');
}

?>